﻿var phoneReg = /^1[345789][0-9]{9}$/;
var pwdReg = /^.{6,16}$/;
var isPhoneRight = false;
var isPwdRight = false;

phone.onkeyup = function(){
  var phoneValue = phone.value;
  if(!phoneReg.test(phoneValue)){
    phoneerror.innerHTML = "对不起，您的手机号格式有误！";
    isPhoneRight = false;
  }else{
    phoneerror.innerHTML = "";
    isPhoneRight = true;
  }
  checkAll();
};

pwd.onkeyup = function(){
  var pwdValue = pwd.value;
  if(!pwdReg.test(pwdValue)){
    pwderror.innerHTML = "对不起，您的密码格式有误！";
    isPwdRight = false;
  }else{
    pwderror.innerHTML = "";
    isPwdRight = true;
  }
  checkAll();
};

function checkAll(){
    if(isPhoneRight&&isPwdRight){
        loginBtn.className = "loginBtn loginBtn_active";
    }else{
        loginBtn.className = "loginBtn";
    }
}

loginBtn.onclick = function(){
    if(this.className!="loginBtn"){
        loginBtn.innerHTML = "登录中";
        loginBtn.style.background = "yellow";
        console.log(loginBtn.style);
        $.post("http://test.hfjava.com/shop/userlogin",  $("form").serialize(),
            function(data){
                loginBtn.innerHTML = "登录";
                loginBtn.style.background = "";
                if(data=="false"){
                    pwderror.innerHTML = "您的用户名或密码有误，请您重试！";
                }else{
                    location.href = "index.html?phone="+phone.value;
                }
            }
        );
    }
};
















